package com.happyclub.lcy.controller;


import com.happyclub.lcy.service.ITeamService;
import com.happyclub.lcy.service.ITravelService;
import com.happyclub.pojo.TbTravel;
import com.happyclub.pojo.TbUser;
import com.happyclub.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;


import java.sql.Time;
import java.util.Date;

import static com.happyclub.utils.Uuid.getUUID;

@RestController
public class TravleController {

    @Autowired
    private ITravelService iTravelService;

    //上传游记
    @RequestMapping(value="travelsContribute")
    public JsonResult  travelsContribute(TbTravel tbTravel, @RequestParam("multipartFile") MultipartFile[] multipartFile ,HttpSession session){
       /* TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        tbTravel.setUserId("zxcnsn34sd");//测试用
        tbTravel.setId(getUUID());
        tbTravel.setIp("ip");
        tbTravel.setLocation("lcoaltion");
        tbTravel.setPublishTime((Time) new Date());
        tbTravel.setCreateTime((Time) new Date());
        if(multipartFile!=null){
            tbTravel.setPhotoAlbumId(tbTravel.getId());
        }
        JsonResult travels = iTravelService.travels(tbTravel, multipartFile);
        return travels;
    }

    @RequestMapping("getTravelsInfo")
    public JsonResult getTravelsInfo(String Id){
        JsonResult travelsInfo = iTravelService.getTravelsInfo(Id);
        return travelsInfo;
    }
    //用户点赞功能
    @RequestMapping("userLike")
    public JsonResult userLike(HttpSession session,String travelId){
        /*TbUser user = (TbUser)session.getAttribute("user");
        String userId =  user.getUserId();*/
        String userId = "fa95b5cfd9ef4d0a94e0a00c0b352436";
        JsonResult jsonResult = iTravelService.userLike(travelId, userId);
        return jsonResult;
    }
}


